home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-11 / trudf.zip / STRIP.C < prev    next >
Text File  |  1993-01-04  |  3KB  |  82 lines

  1. /*********
  2. *
  3. * STRIP.C
  4.  
  5. *   Author : Jean-Pierre van Melis
  6. * Compiled : with Microsoft C 5.1
  7. *   Object : can only be used in conjunction with Clipper summer '87
  8.  
  9. *  Syntax: STRIP( <expC> )
  10. *  Return: All non-alphanumeric characters are removed, and spaces
  11. *          are added to keep the initial length (for indexing purposes).
  12. *          and all characters are made uppercase to gain speed.
  13. *
  14. *          INPUT                  RETURN
  15. *          ---------------------- ----------------------------------
  16. *           "v/d Broek B.V.  "    "VDBROEKBV       "
  17. *
  18. *
  19. *        mNAAM = "v/d Broek B.V.    "
  20. *        USE namen
  21. *        INDEX ON STRIP(naam) TO naam
  22. *        SEEK TRIM(STRIP(mNAAM))
  23. *        IF FOUND()
  24. *           ? naam
  25. *        ENDIF
  26. *
  27. *
  28. *     output: "v/d Broek B.V.    "
  29. *********/
  30.  
  31. #include "jplib.h"
  32.  
  33. CLIPPER strip()
  34.  
  35. {
  36.  
  37.    byte *par;                                      /* pointer to input */
  38.    byte *retstr;                                   /* pointer to output */
  39.  
  40.    quant leng;                                     /* leng of string */
  41.    quant n1;                                       /* offset input */
  42.    quant n2;                                       /* offset output */
  43.  
  44.    Boolean error;
  45.  
  46.    error = TRUE;
  47.  
  48.    if(PCOUNT == 1 && ISCHAR(1))
  49.    {
  50.       par    = _parc(1);                           /* receive pointer from clipper */
  51.       leng   = (quant) _parclen(1);                /* receive leng from clipper */
  52.  
  53.       retstr = _exmgrab(leng+1);                   /* Allocate memory */
  54.  
  55.       if(retstr)                                   /* Enough memory available */
  56.       {
  57.          error = FALSE;                            /* No errors */
  58.          n2    = 0;                                /* point to first character */
  59.  
  60.          for(n1 = 0; n1 < leng; n1++)              /* parse input till end of input*/
  61.          {
  62.             if(islower(par[n1]))                   /* character is lowercase */
  63.               retstr[n2++] = (par[n1] + ('A'-'a'));/* convert to uppercase */
  64.             else if(isdigit(par[n1]) || isupper(par[n1])) /* is alphanumeric */
  65.               retstr[n2++] = par[n1];              /* copy from input */
  66.          }
  67.          while(n2 < leng)                          /* fill rest with spaces */
  68.             retstr[n2++] = SPACEC;
  69.  
  70.          retstr[n2] = NULLC;                       /* terminate with null */
  71.       }
  72.    }
  73.    if(error)
  74.       _retc(NULLS);                                /* return null string */
  75.    else
  76.    {
  77.       _retclen(retstr, leng);                      /* return string with length */
  78.       _exmback(retstr, leng+1);                    /* deallocate memory */
  79.    }
  80.    return;
  81. }
  82.